//
//  main.m
//  03-NSStringAndArrayHomeWork
//
//  Created by LL.F on 16/7/6.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Book.h"
#import "BookManager.h"

int main(int argc, const char * argv[]) {
    
    // 1. 截取字符串 "20|https://www.baidu.com" 中 "|" 前面和后⾯的字符串, 并输出
    //方法一:
    NSString *string = [NSString stringWithFormat:@"20|https://www.baidu.com"];
    NSString *frontString = [string substringToIndex:2];
    NSString *backString = [string substringFromIndex:3];
    NSLog(@"%@\n%@", frontString, backString);
    //方法二:
    NSArray *arr = [string componentsSeparatedByString:@"|"];
    for (NSString *str in arr) {
        NSLog(@"%@", str);
    }
    
    // 2. 向可变数组里存储 int、float、double、BOOL类型等数据(不能使用字面量)
    NSMutableArray *array = [NSMutableArray array];
    int member1 = 10;
    float member2 = 2.8;
    double member3 = 3.6356;
    BOOL member4 = YES;
    [array addObject:[NSNumber numberWithInt:member1]];
    [array addObject:[NSNumber numberWithFloat:member2]];
    [array addObject:[NSNumber numberWithDouble:member3]];
    [array addObject:[NSNumber numberWithBool:member4]];
    NSLog(@"%@", array);
    
    // 3. 实现图书管理系统(BookManager类)：
    //    1). 使用数组管理所有书籍(Book类)。
    //    2). BookManager类属性数组可以添加、删除。
    //    3). 可以从数组根据书名查找书籍，并修改书籍的价格。
    //    4). 展示所有书籍清单（书名）
     
    BookManager *bookManager = [[BookManager alloc] init];
    bookManager.libraryArray = [NSMutableArray array];
    
    Book *book1 = [Book bookWithName:@"红楼梦" Price:55];
    Book *book2 = [Book bookWithName:@"水浒传" Price:22.2];
    Book *book3 = [Book bookWithName:@"三国演义" Price:10.56];
    Book *book4 = [Book bookWithName:@"西游记" Price:38.33];
    Book *book5 = [Book bookWithName:@"最好的我们" Price:888];
    
    // 添加书籍
    [bookManager addBook:book1];
    [bookManager addBook:book2];
    [bookManager addBook:book3];
    [bookManager addBook:book4];
    
    // 删除书籍
    [bookManager deleteBook:book4];
    
    // 查找书籍并修改价格
    [bookManager findBook:book5];
    
    //显示所有书籍清单
    [bookManager showAllBooks];
    
    
    return 0;
}
